#pragma once
#include "creature.h"

/*草，性别flag全部是2，行动模式只有生长和繁殖*/
class Grass : public Creature
{
public:
	Grass();
	Grass(int name);
	Grass(int name, int x, int y, Flag flag);
	virtual void action();
	virtual void eat();
	virtual void breed();
	virtual void record();
};

Grass::Grass() {}

Grass::Grass(int name, int x, int y, Flag flag)
{
	m_flag = flag; /*先把标签赋给新生物，确定种族和上限，其他的之后覆盖*/
	/*创建一个生物，随机生成数值,x和y坐标固定*/
	m_position.x = x;
	m_position.y = y;
	m_name = name;
	m_age = 1;													 /*新生物的年龄为1*/
	m_hp = m_flag.hp_up / 2 + (rand() % (m_flag.hp_up / 2 + 1)); /*生命值在上限一半到上限内生成*/
	m_hunger = m_flag.hunger_full / 2;							 /*饥饿值为半饱*/
	m_flag.gender = 1 + (rand() % 2);
}

Grass::Grass(int name)
{
	m_flag = {3, 3, 1, 0, 0, 10, 100, 100, 1, 1};
	m_name = name;
	m_age = rand() % m_flag.age_up;												 /*年龄在上限内随机生成*/
	m_hp = m_flag.hp_up / 2 + (rand() % (m_flag.hp_up / 2 + 1));				 /*生命值在上限一半到上限内生成*/
	m_hunger = m_flag.hunger_full / 2 + (rand() % (m_flag.hunger_full / 2 + 1)); /*饥饿值在饱一半到全饱内生成*/
	m_flag.gender = 1 + (rand() % 2);
	m_position = {rand() % 50, rand() % 50};
}

void Grass::action() /*草没有移动和视力，故只需要分配模式为进食（生长）和繁衍*/
{
	situation();
	switch (m_flag.mode)
	{
	case 1:
		eat() /*草单独调用*/;
		break;
	case 2:
		breed(); /*草是往四周新建四个对象*/
		break;
	default:
		break;
	}
}
/*直接加40饥饿值*/
void Grass::eat()
{
	m_hunger += 40;
}
void Grass::breed() /*草是向上下左右四格生成子类*/
{
	m_hp -= 50;
	/*草是直接新建，所以新草的编号就是总数后4个，最后把总数再加4满足范围*/
	/*为避免冲突，应先检测草位置有无占位，如有则不生成*/
	nature.grass[nature.num.grass + 1] = new Grass((nature.num.grass + 1), (m_position.x + 1), m_position.y, nature.grass[m_name]->m_flag);
	nature.grass[nature.num.grass + 2] = new Grass((nature.num.grass + 2), (m_position.x - 1), m_position.y, nature.grass[m_name]->m_flag);
	nature.grass[nature.num.grass + 3] = new Grass((nature.num.grass + 3), m_position.x, (m_position.y + 1), nature.grass[m_name]->m_flag);
	nature.grass[nature.num.grass + 4] = new Grass((nature.num.grass + 4), m_position.x, (m_position.y - 1), nature.grass[m_name]->m_flag);
	nature.num.grass += 4;
}
/*草没有记录，所以直接空函数*/
void Grass::record()
{
}
